package com.yinxin.service.impl;

import com.yinxin.Util.ResultUtil;
import com.yinxin.entity.Result.Result;
import com.yinxin.mapper.UserMapper;
import com.yinxin.entity.User;
import com.yinxin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: YinXin
 * @Date: 2021/9/10 17:05
 * @Version: 1.0
 * @description:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public Result getUserInfo() {
            List<User> userList = userMapper.selectUser();
            Result result= ResultUtil.success(userList);
            return result;
    }

    @Override
    public Result deleteUser(Integer id) {
        String msg="";
            if(userMapper.deleteUserById(id)==1){
                msg="删除成功！";
            }else {
                msg="删除失败！";
            };
            Result result=ResultUtil.success(msg);
            return result;
    }

    @Override
    public Result updateUser(User user) {
        String msg="";
        if(userMapper.updateUserById(user)==1){
            msg="更新成功！";
        }else {
            msg="更新失败！";
        };
        Result result = ResultUtil.success(msg);
        return result;
    }

    @Override
    public Result insertUser(User user) {
        String msg="";
        if(userMapper.insertUser(user)==1){
            msg="插入成功！";
        }else {
            msg="插入失败！";
        };
        Result result = ResultUtil.success(msg);
        return result;
    }
}
